home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0056_Is String in File.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  4KB  |  90 lines

  1.  
  2. PROGRAM HI_There;
  3. (*   Syntax:  there  textfile  number  /quotedstring
  4.    where textfile is filename, number is a line offset, & quotedstring is a
  5.    group of characters without embedded control codes.  Purpose is to go to a
  6.    given line offset in the text file, search that line for the string, and
  7.    report via DOS error 1=True or 0=False depending upon if it was there.
  8.  
  9. Example:  there.exe  there.pas  0  /'program'
  10.    would return error level 1 (True) since 'program' is on the first line.
  11.  
  12. Author:  John Howard                                   Date:  January 5, 1994
  13. Copyright 1994  Howard International,  P.O. Box 34633, NKC, MO 64116
  14.  
  15. Restrictions:  You are free to use this program but I retain commercial
  16.                ownership.  You may not charge someone to use this program.
  17. Note:          Case sensitive.  Front or Back quote is removed.  No trailing
  18.                whitespace is removed from the string.  Zero-based line offset.
  19.                Returns DOS error level values: 0 thru 4 ******* *)
  20. {$DEFINE debug}
  21. VAR
  22.    F: text;          (* CHAIN.TXT dropfile used by WWIV BBS *)
  23.    LineNo: word;     (* Line Number from 0..65535 *)
  24.    S: string;        (* Substring of 1..255 characters *)
  25.    CmdLine: string;  (* string[127] command-line string *)
  26.  
  27.    Test: string;     (* temporary search line *)
  28.    Code: integer;    (* temporary result of VAL conversion *)
  29.    I: word;          (* temporary index of current line *)
  30.    B: byte;          (* temporary index of command-line string *)
  31. BEGIN { MAIN }
  32.       {$I-}  (* Turn OFF input/output checking to prevent run-time error *)
  33.       (* Open an existing text file *)
  34.       Assign(F, ParamStr(1));
  35.       Reset(F);
  36.       {$I+}  (* Turn ON I/O *)
  37.       if (IOResult <> 0) then Halt(2); {writeln('File not found');}
  38.       (* Get text from command line and convert into a number *)
  39.       Val(ParamStr(2), LineNo, Code);
  40.       if Code <> 0 then Halt(3); {writeln('Bad number at position: ', Code);}
  41.       (* Get quoted string or un-broken string. NO end whitespace removed! *)
  42.       Move(Mem[PrefixSeg:$80], CmdLine, Mem[PrefixSeg:$80] + 1);
  43.       S := CmdLine;
  44. {$IFDEF debug}                  writeln(S);  {$ENDIF}
  45.       B := Pos( '/', S);
  46. {$IFDEF debug}                  writeln('CmdLine pos ', B);  {$ENDIF}
  47.       Delete(S, 1, B);
  48.       if S[1] = #39 then Delete(S, 1, 1);                   (* start quote *)
  49.       if S[Length(S)] = #39 then Delete(S, Length(S), 1);   (* end quote *)
  50.       if S = '' then Halt(4); {writeln('Empty string not allowed');}
  51. {$IFDEF debug}                  writeln('Line: ', LineNo);  {$ENDIF}
  52. {$IFDEF debug}                  writeln(S);  {$ENDIF}
  53.       (* Go to specified line within text file *)
  54.       I := 0;
  55.       while not Eof(F) do
  56.           begin
  57.           Readln(F, Test);
  58. {$IFDEF debug}                  writeln(Test);  {$ENDIF}
  59.           if (I = LineNo) then
  60.              begin
  61.              if Pos(S, Test) > 0 then
  62.              (* String S matched substr Test at position *)
  63.                 begin
  64.                 Close(F);
  65. {$IFDEF debug}                  writeln('True ', I);  {$ENDIF}
  66.                 Halt(1);   (* Return True *)
  67.                 end
  68.              else
  69.              (* Search string not found *)
  70.                 begin
  71.                 Close(F);
  72. {$IFDEF debug}                  writeln('False ', I);  {$ENDIF}
  73.                 Halt(0);   (* Return False *)
  74.                 end;
  75.              end;
  76.           (* Move to the next line *)
  77.           if (I < 65535) then
  78.              INC(I)               {I := I + 1}
  79.           else
  80.              begin
  81.              Close(F);
  82.              Halt(0);
  83.              end;
  84.           end;  {while}
  85.       (* Close the existing text file *)
  86.       Close(F);
  87.       Halt(0);     (* Return False *)
  88. END.  { MAIN }
  89.  
  90.